package com.local.controller.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.local.model.LocalParkSpaceCheck;
import com.local.model.LocalRepeatImport;
import com.local.model.LocalRota;
import com.local.model.LocalTemporaryCheck;
import com.local.page.LocalRotaPage;
import com.local.service.face.LocalParkSpaceCheckService;
import com.local.service.face.LocalRepeatImportService;
import com.local.service.face.LocalRotaService;
import com.local.service.face.LocalRotaUserService;
import com.local.service.face.LocalTemporaryCheckService;
import com.qianhai.common.constants.CommonContans;
import com.qianhai.common.controller.BaseController;
import com.qianhai.common.utils.Tools;

@RestController
@RequestMapping(value = "/admin/rota", method = RequestMethod.POST)
public class LocalRotaController extends BaseController
{
	@Autowired
	private LocalRotaService localRotaService;
	
	@Autowired
	private LocalRotaUserService localRotaUserService;
	
	@Autowired
	private LocalTemporaryCheckService localTemporaryCheckService;
	
	@Autowired
	private LocalParkSpaceCheckService localParkSpaceCheckService;
	
	@Autowired
	private LocalRepeatImportService localRepeatImportService;
	
	
	/**
	 * 
	 * 方法描述：查询会员列表并分页
	 * @Title: queryRotaByPage 
	 * @param @param pageInfo
	 * @param @return
	 * @return ModelMap
	 * @user zw
	 * 2015年4月7日
	 * @throws
	 */
	@RequestMapping(value = "/queryRotaByPage.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryRotaByPage(@RequestBody LocalRotaPage<LocalRota> pageInfo)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localRotaService.queryByPage(pageInfo);
			resultMap.put(CommonContans.STRUTS_DATA, pageInfo);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
	@RequestMapping(value = "/addOrModifyLocalRota.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap addOrModifyLocalRota(
			@RequestBody LocalRota localRota)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			if(!Tools.isEmpty(this.getLoginUser())){
				localRota.setUserId(this.getLoginUser().getUuid());
				localRota.setUserName(this.getLoginUser().getLoginName());
			}
			localRotaService.saveOrUpdateLocalRota(localRota);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
	@RequestMapping(value = "/queryLocalRotaById.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryLocalRotaById(String uuid)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			LocalRota localRota =localRotaService.selectByPrimaryKey(uuid);
			resultMap.put(CommonContans.STRUTS_DATA, localRota);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
	@RequestMapping(value = "/deleteById.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap deleteById(String uuid)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localRotaService.deleteByIdAndRotaUser(uuid);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
	/**
	 * 
	 * @方法名称: queryRotaUser
	 * @描述: 查询班次人员列表
	 * @参数:
	 * @param page
	 * @return
	 * @返回类型: ModelMap
	 * @作者:zengqj
	 * @可能抛出异常:
	 */
	@RequestMapping(value = "/queryRotaUser.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryRotaUser(@RequestBody LocalRotaPage<LocalRota> page)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			List<LocalRota> list = localRotaService.queryRotaUser(page);
			page.setData(list);
			resultMap.put(CommonContans.STRUTS_DATA, page);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
	@RequestMapping(value = "/queryRotaUserOther.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryRotaUserOther(@RequestBody LocalRotaPage<LocalRota> page)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			List<LocalRota> list = localRotaService.queryRotaUserOther(page);
			page.setData(list);
			resultMap.put(CommonContans.STRUTS_DATA, page);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * 方法描述：删除rotaUser表中id为rotaUserID,然后添加
	 * @Title: updateRotaUser 
	 * @param @param localRota
	 * @param @return
	 * @return ModelMap
	 * @user Administrator
	 * 2015年10月4日
	 * @throws
	 */
	@RequestMapping(value = "/updateRotaUser.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap updateRotaUser(@RequestBody LocalRota localRota)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localRotaUserService.updateByRotaUuid(localRota.getUuid(),localRota.getUserIdString());
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
	@RequestMapping(value = "/addOrModifyLocalTemporaryCheck.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap addOrModifyLocalTemporaryCheck(
			@RequestBody LocalTemporaryCheck localTemporaryCheck)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localTemporaryCheckService.saveOrUpdateLocalTemporaryCheck(localTemporaryCheck);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * 方法描述：滚动计费开关
	 * @Title: addOrModifyLocalRepeatImport 
	 * @param @param localRepeatImport
	 * @param @return
	 * @return ModelMap
	 * @user Administrator
	 * 2016年6月3日
	 * @throws
	 */
	@RequestMapping(value = "/addOrModifyLocalRepeatImport.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap addOrModifyLocalRepeatImport(
			@RequestBody LocalRepeatImport localRepeatImport)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localRepeatImportService.saveOrUpdateLocalRepeatImport(localRepeatImport);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	@RequestMapping(value = "/LoadLocalTemporaryCheck.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap LoadLocalTemporaryCheck(
			@RequestBody LocalTemporaryCheck localTemporaryCheck)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			resultMap.put(CommonContans.STRUTS_DATA, localTemporaryCheckService.queryLocalTemporaryCheck());
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	@RequestMapping(value = "/LoadLocalRepeatImport.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap LoadLocalRepeatImport(
			@RequestBody LocalRepeatImport localRepeatImport)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			resultMap.put(CommonContans.STRUTS_DATA, localRepeatImportService.queryLocalRepeatImport());
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * 方法描述：进场控制(车位已满)
	 * @Title: addOrModifyLocalParkSpaceCheck 
	 * @param @param localParkSpaceCheck
	 * @param @return
	 * @return ModelMap
	 * @user Administrator
	 * 2016年6月3日
	 * @throws
	 */
	@RequestMapping(value = "/addOrModifyLocalParkSpaceCheck.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap addOrModifyLocalParkSpaceCheck(
			@RequestBody LocalParkSpaceCheck localParkSpaceCheck)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localParkSpaceCheckService.saveOrUpdateLocalParkSpaceCheck(localParkSpaceCheck);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	@RequestMapping(value = "/LoadLocalParkSpaceCheck.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap LoadLocalParkSpaceCheck(
			@RequestBody LocalParkSpaceCheck localParkSpaceCheck)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			resultMap.put(CommonContans.STRUTS_DATA, localParkSpaceCheckService.queryLocalParkSpaceCheck());
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
}
